/*
链接：https://ac.nowcoder.com/acm/contest/43898/B
来源：牛客网

A string s0 is given, only consisting of 0 and 1. The j-th character of the string si is si,j , when the index starts from 0. We defifine si (i ≥ 1) as follows:
The length of si is less than the length of si−1 by 1. And for each letter si,j in the string si ,
si,j = max(si−1,j , si−1,j+1).
For example, if s0 = 1010, then s1 = 111, s2 = 11, etc.
f(s) represents the number of 1 in the string s. Please print the result of Σ𝑖=0𝑘𝑓(𝑠𝑖)Σ i=0kf(si).
输入描述:
The fifirst line contains one integer t(1 ≤ t ≤ 105 ) — the number of test cases.
The fifirst line of each test case contains two integers n, and k (1 ≤ n ≤ 3 · 105 , 1 ≤ k ≤ n) — the length of s0 and the variable in Σ𝑖=0𝑘𝑓(𝑠𝑖)Σ i=0kf(s i).
The second line contains the string s0 — the original string mentioned above.
It is guaranteed that the sum of n over all test cases does not exceed 3 · 105 .
输出描述:
For each test case print one integer — the result of Σ𝑖=0𝑘𝑓(𝑠𝑖)Σi=0kf(si).
*/
#include<bits/stdc++.h>
#define endl "\n"
#define ll long long
#define all(rq) rq.begin(),rq.end()
#define max(a,b) (a<b?b:a)
#define min(a,b) (a<b?a:b)

using namespace std;
const int INF=0x3f3f3f3f;

int main(){
	int t;
	cin>>t;
	while(t--){
		int n,k;
		cin>>n>>k;
		string str;
		cin>>str;
		
		vector<ll> len(n+1); //len[i]0的连续长度为i的区间个数 
		vector<ll> f(k+1);
		ll cnt=0;
		
		ll pos=-1;
		for(ll i=0;i<n;i++){
			if(str[i]=='0'){
				cnt++;
				if(i>=cnt){
					len[cnt]++;
				}
			}else{
				
				if(pos==-1){
					pos=i;
				}
				cnt=0;
				f[0]++;
			}
		}
		
		len[0]=0;
		
		if(pos==-1){
			cout<<0<<endl;
			break;
		}else{
//			cout<<endl;
			for(int i=1;i<=k;i++){
				f[i]=f[i-1]+len[i]-(pos<i); //f[i]为 f[i-1]+长度超过i并且于当前区间可以产生交集的连续0的的数量-当前区间以前是否可能产生1
				
//				cout<<"f["<<i<<"]:"<<f[i]<<' ';
			}
			
//			cout<<endl;
		}
		
		ll ans=accumulate(f.begin(),f.end(),0);
		
		cout<<ans<<endl;
	} 
	return 0;
}